package org.example.线程池;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class 自定义线程工厂 {

    public static void main(String[] args) {
            ThreadFactory  threadFactory = new ThreadFactory(){
                @Override
                public Thread newThread(Runnable r) {
                    Thread thread = new Thread(r);
                    thread.setName( "线程-" + thread.getId()); // 设置一个线程名称，方便异常追踪
                    // 可以在这里设置其他线程属性，例如优先级、是否为守护线程等
                    return thread;
                }
            };

            ThreadPoolExecutor s = new ThreadPoolExecutor(2, 4, 60, TimeUnit.SECONDS,
                    new ArrayBlockingQueue<Runnable>(4), threadFactory,
                    new ThreadPoolExecutor.CallerRunsPolicy());
        }

}
